allow setting different name for accuracy field

stvnrlly 10 years ago
parent
commit
147617e771
1 changed files with 9 additions and 3 deletions
  1. 9 3
      app/models/agents/user_location_agent.rb

+ 9 - 3
app/models/agents/user_location_agent.rb

@@ -11,7 +11,7 @@ module Agents
11 11
 
12 12
         Your POST path will be `https://#{ENV['DOMAIN']}/users/#{user.id}/update_location/:secret` where `:secret` is specified in your options.
13 13
 
14
-        If you want to only keep more precise locations, set `max_accuracy` to the upper bound, in meters.
14
+        If you want to only keep more precise locations, set `max_accuracy` to the upper bound, in meters. The default name for this field is `accuracy`, but you can change this by setting a value for `accuracy_field`.
15 15
       MD
16 16
     end
17 17
 
@@ -73,8 +73,14 @@ module Agents
73 73
     def handle_payload(payload)
74 74
       location = Location.new(payload)
75 75
 
76
-      if location.present? && (!interpolated[:max_accuracy].present? || !payload["accuracy"] || payload["accuracy"] < interpolated[:max_accuracy])
77
-        if !payload["accuracy"]
76
+      if interpolated[:accuracy_field].present?
77
+        accuracy_field = interpolated[:accuracy_field]
78
+      else
79
+        accuracy_field = 'accuracy'
80
+      end
81
+
82
+      if location.present? && (!interpolated[:max_accuracy].present? || !payload[accuracy_field] || payload[accuracy_field] < interpolated[:max_accuracy])
83
+        if !payload[accuracy_field]
78 84
           log "Accuracy field missing; all locations will be kept"
79 85
         end
80 86
         create_event payload: payload, location: location